package me.sealer.utils;

import me.sealer.utils.enums.PrintTarget;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Created by sealer on 08-05-2017.
 */
public class PrintUtil {
    public static void printString(String content, PrintTarget target, String descPath) {
        if (PrintTarget.CONSOLE == target) {
            System.out.print(content);
        } else if (PrintTarget.FILE == target) {
            printToFile(content, descPath);
        }
    }

    private static void printToFile(String content, String descPath) {
        if (descPath == null || "".equals(descPath)) {
            System.out.println("文件名不能为空！");
            return;
        }
        File file = new File(descPath);
        try {
            FileWriter fw = new FileWriter(file, true);
            fw.write(content);
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
